{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fba0fda3",
   "metadata": {},
   "source": [
    "**2022/9/25 礼仪的week05**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef7f361f",
   "metadata": {},
   "source": [
    "## 本周知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "283df915",
   "metadata": {},
   "source": [
    "> 1.控制流\n",
    ">> 1.条件判断\n",
    ">>\n",
    ">> 2.循环遍历"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "799ca52e",
   "metadata": {},
   "source": [
    "> 2.随机函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f6c2410",
   "metadata": {},
   "source": [
    "> 3.时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d230bf1",
   "metadata": {},
   "source": [
    "## 1.控制流"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8528e56b",
   "metadata": {},
   "source": [
    "### (一)条件判断"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eecc5d00",
   "metadata": {},
   "source": [
    "* 知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3241eb10",
   "metadata": {},
   "source": [
    "> 1.赋值 是 “=”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c02b0c4",
   "metadata": {},
   "source": [
    "> 2.判断是否两者相等 是 “==”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e27d9b9",
   "metadata": {},
   "source": [
    "> 3.代码中出现的变量，必须先定义，否则： name 变量 is not defined"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4bd28bc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Party!\n"
     ]
    }
   ],
   "source": [
    "# 先定义变量 today\n",
    "\n",
    "today = \"Saturday\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dc6243b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Recover, then rest.\n"
     ]
    }
   ],
   "source": [
    "today = \"Sunday\"\n",
    "condition = \"Headache\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10b6931f",
   "metadata": {},
   "source": [
    "# 关于if else 条件判断实践："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c2d3e2b",
   "metadata": {},
   "source": [
    "## 判断今天是周几，如果是周一，有python课，好开心呀；如果不是，期待周一呀。（time可以帮我们知道今天周几）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbe4bee3",
   "metadata": {},
   "source": [
    "## 判断今天是周几，如果是周一，请判断现在是否正在上python课。（time可以帮我们知道现在是几点钟几分钟"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "325d7c9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "942ee8ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=25, tm_hour=23, tm_min=9, tm_sec=34, tm_wday=6, tm_yday=268, tm_isdst=0)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1d3d8ecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b356fa8e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周几 6\n",
      "几点 23\n",
      "几分 10\n",
      "期待周一呀\n"
     ]
    }
   ],
   "source": [
    "# tm_day 0-6 0是周一\n",
    "# 准备工作：准备所有可能用到的变量\n",
    "wday = time.localtime().tm_wday\n",
    "print(\"周几\",wday)\n",
    "today_hour = time.localtime().tm_hour\n",
    "print(\"几点\",today_hour)\n",
    "today_min = time.localtime().tm_min\n",
    "print(\"几分\",today_min)\n",
    "# 条件判断，完成：\n",
    "# 关于if eles 条件判断实践：\n",
    "## 判断今天是周几，如果是周一，有python课，好开心呀；如果不是，期待周一呀。（time可以帮我们知道今天周几）\n",
    "## 判断今天是周几，如果是周一，请判断现在是否正在上python课。（time可以帮我们知道现在是几点钟几分钟）\n",
    "\n",
    "if wday == 0:\n",
    "    print(\"今天是周一，有python课，好开心呀\")\n",
    "    if 9 < today_hour < 12:\n",
    "        print(\"现在是\",today_hour,\"点\",today_min,\"分\",\"正在上python\")\n",
    "    elif today_hour == 9:\n",
    "        if today_min >= 45:\n",
    "            print(\"正在上python\")\n",
    "        elif today_min == 30:\n",
    "            print(\"马上就要上python课了\")\n",
    "        else:\n",
    "            print(\"手机弹出框，马上就要上python了，好激动呀\")\n",
    "    else:    \n",
    "        print(\"没有在上python\")\n",
    "else:\n",
    "    print(\"期待周一呀\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68c29a6f",
   "metadata": {},
   "source": [
    "# 2.循环遍历(for)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "888828ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "27af8efa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8aee08b",
   "metadata": {},
   "source": [
    "# 上述 i 和 ch 都是变量，可以根据我们的需求定义变量名"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94ebff25",
   "metadata": {},
   "source": [
    "# 每一次执行，赋值一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f0e229dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# range(): 范围，区间\n",
    "for num in range(10):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3dd63e3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.range()是一个数字/数值生成器，每次增加1\n",
    "# 2.range() 包含有起始点start（默认为0）,终止点stop，以及步长step（默认为1）\n",
    "\n",
    "range(5) #给定了默认的起点是 0，终结点是 5，产生了5-0个数值，默认每次增加1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1debc661",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0, 5)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a0eb74a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(5, 10)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5,10) # 自定义起始点 5，终结点 10，产生了10-5个数值，默认每次增加1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c69480c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "17c1e1d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10, 3)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0,10,3)  # 自定义起始点 0，终结点 10，自定义每次增加3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7c65ca5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 9]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06fd438c",
   "metadata": {},
   "source": [
    "# **请参考以下，获取广州南方学院校园动态的数据**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "20e8ba49",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http://www.nfu.edu.cn/xxyw/index0.htm\n",
      "http://www.nfu.edu.cn/xxyw/index1.htm\n",
      "http://www.nfu.edu.cn/xxyw/index2.htm\n",
      "http://www.nfu.edu.cn/xxyw/index3.htm\n",
      "http://www.nfu.edu.cn/xxyw/index4.htm\n",
      "http://www.nfu.edu.cn/xxyw/index5.htm\n",
      "http://www.nfu.edu.cn/xxyw/index6.htm\n",
      "http://www.nfu.edu.cn/xxyw/index7.htm\n",
      "http://www.nfu.edu.cn/xxyw/index8.htm\n",
      "http://www.nfu.edu.cn/xxyw/index9.htm\n",
      "http://www.nfu.edu.cn/xxyw/index10.htm\n",
      "http://www.nfu.edu.cn/xxyw/index11.htm\n",
      "http://www.nfu.edu.cn/xxyw/index12.htm\n",
      "http://www.nfu.edu.cn/xxyw/index13.htm\n",
      "http://www.nfu.edu.cn/xxyw/index14.htm\n",
      "http://www.nfu.edu.cn/xxyw/index15.htm\n",
      "http://www.nfu.edu.cn/xxyw/index16.htm\n",
      "http://www.nfu.edu.cn/xxyw/index17.htm\n",
      "http://www.nfu.edu.cn/xxyw/index18.htm\n",
      "http://www.nfu.edu.cn/xxyw/index19.htm\n",
      "http://www.nfu.edu.cn/xxyw/index20.htm\n",
      "http://www.nfu.edu.cn/xxyw/index21.htm\n",
      "http://www.nfu.edu.cn/xxyw/index22.htm\n",
      "http://www.nfu.edu.cn/xxyw/index23.htm\n",
      "http://www.nfu.edu.cn/xxyw/index24.htm\n",
      "http://www.nfu.edu.cn/xxyw/index25.htm\n",
      "http://www.nfu.edu.cn/xxyw/index26.htm\n",
      "http://www.nfu.edu.cn/xxyw/index27.htm\n",
      "http://www.nfu.edu.cn/xxyw/index28.htm\n",
      "http://www.nfu.edu.cn/xxyw/index29.htm\n",
      "http://www.nfu.edu.cn/xxyw/index30.htm\n",
      "http://www.nfu.edu.cn/xxyw/index31.htm\n",
      "http://www.nfu.edu.cn/xxyw/index32.htm\n",
      "http://www.nfu.edu.cn/xxyw/index33.htm\n",
      "http://www.nfu.edu.cn/xxyw/index34.htm\n",
      "http://www.nfu.edu.cn/xxyw/index35.htm\n",
      "http://www.nfu.edu.cn/xxyw/index36.htm\n",
      "http://www.nfu.edu.cn/xxyw/index37.htm\n",
      "http://www.nfu.edu.cn/xxyw/index38.htm\n",
      "http://www.nfu.edu.cn/xxyw/index39.htm\n",
      "http://www.nfu.edu.cn/xxyw/index40.htm\n",
      "http://www.nfu.edu.cn/xxyw/index41.htm\n",
      "http://www.nfu.edu.cn/xxyw/index42.htm\n",
      "http://www.nfu.edu.cn/xxyw/index43.htm\n",
      "http://www.nfu.edu.cn/xxyw/index44.htm\n",
      "http://www.nfu.edu.cn/xxyw/index45.htm\n",
      "http://www.nfu.edu.cn/xxyw/index46.htm\n",
      "http://www.nfu.edu.cn/xxyw/index47.htm\n",
      "http://www.nfu.edu.cn/xxyw/index48.htm\n",
      "http://www.nfu.edu.cn/xxyw/index49.htm\n",
      "http://www.nfu.edu.cn/xxyw/index50.htm\n",
      "http://www.nfu.edu.cn/xxyw/index51.htm\n",
      "http://www.nfu.edu.cn/xxyw/index52.htm\n",
      "http://www.nfu.edu.cn/xxyw/index53.htm\n",
      "http://www.nfu.edu.cn/xxyw/index54.htm\n",
      "http://www.nfu.edu.cn/xxyw/index55.htm\n",
      "http://www.nfu.edu.cn/xxyw/index56.htm\n",
      "http://www.nfu.edu.cn/xxyw/index57.htm\n",
      "http://www.nfu.edu.cn/xxyw/index58.htm\n",
      "http://www.nfu.edu.cn/xxyw/index59.htm\n",
      "http://www.nfu.edu.cn/xxyw/index60.htm\n",
      "http://www.nfu.edu.cn/xxyw/index61.htm\n",
      "http://www.nfu.edu.cn/xxyw/index62.htm\n",
      "http://www.nfu.edu.cn/xxyw/index63.htm\n",
      "http://www.nfu.edu.cn/xxyw/index64.htm\n",
      "http://www.nfu.edu.cn/xxyw/index65.htm\n",
      "http://www.nfu.edu.cn/xxyw/index66.htm\n",
      "http://www.nfu.edu.cn/xxyw/index67.htm\n",
      "http://www.nfu.edu.cn/xxyw/index68.htm\n",
      "http://www.nfu.edu.cn/xxyw/index69.htm\n",
      "http://www.nfu.edu.cn/xxyw/index70.htm\n",
      "http://www.nfu.edu.cn/xxyw/index71.htm\n",
      "http://www.nfu.edu.cn/xxyw/index72.htm\n",
      "http://www.nfu.edu.cn/xxyw/index73.htm\n",
      "http://www.nfu.edu.cn/xxyw/index74.htm\n",
      "http://www.nfu.edu.cn/xxyw/index75.htm\n",
      "http://www.nfu.edu.cn/xxyw/index76.htm\n",
      "http://www.nfu.edu.cn/xxyw/index77.htm\n",
      "http://www.nfu.edu.cn/xxyw/index78.htm\n",
      "http://www.nfu.edu.cn/xxyw/index79.htm\n",
      "http://www.nfu.edu.cn/xxyw/index80.htm\n",
      "http://www.nfu.edu.cn/xxyw/index81.htm\n",
      "http://www.nfu.edu.cn/xxyw/index82.htm\n",
      "http://www.nfu.edu.cn/xxyw/index83.htm\n",
      "http://www.nfu.edu.cn/xxyw/index84.htm\n",
      "http://www.nfu.edu.cn/xxyw/index85.htm\n",
      "http://www.nfu.edu.cn/xxyw/index86.htm\n",
      "http://www.nfu.edu.cn/xxyw/index87.htm\n",
      "http://www.nfu.edu.cn/xxyw/index88.htm\n",
      "http://www.nfu.edu.cn/xxyw/index89.htm\n",
      "http://www.nfu.edu.cn/xxyw/index90.htm\n",
      "http://www.nfu.edu.cn/xxyw/index91.htm\n",
      "http://www.nfu.edu.cn/xxyw/index92.htm\n",
      "http://www.nfu.edu.cn/xxyw/index93.htm\n",
      "http://www.nfu.edu.cn/xxyw/index94.htm\n",
      "http://www.nfu.edu.cn/xxyw/index95.htm\n",
      "http://www.nfu.edu.cn/xxyw/index96.htm\n",
      "http://www.nfu.edu.cn/xxyw/index97.htm\n",
      "http://www.nfu.edu.cn/xxyw/index98.htm\n",
      "http://www.nfu.edu.cn/xxyw/index99.htm\n",
      "http://www.nfu.edu.cn/xxyw/index100.htm\n",
      "http://www.nfu.edu.cn/xxyw/index101.htm\n",
      "http://www.nfu.edu.cn/xxyw/index102.htm\n",
      "http://www.nfu.edu.cn/xxyw/index103.htm\n",
      "http://www.nfu.edu.cn/xxyw/index104.htm\n",
      "http://www.nfu.edu.cn/xxyw/index105.htm\n",
      "http://www.nfu.edu.cn/xxyw/index106.htm\n",
      "http://www.nfu.edu.cn/xxyw/index107.htm\n",
      "http://www.nfu.edu.cn/xxyw/index108.htm\n",
      "http://www.nfu.edu.cn/xxyw/index109.htm\n"
     ]
    }
   ],
   "source": [
    "# 实践：数据挖掘——获取页面URL队列\n",
    "学校要闻 = \"xxyw\"\n",
    "学校要闻_page = 110\n",
    "\n",
    "通知公告 = \"tzgg\"\n",
    "for page in range(110):\n",
    "    print(\"http://www.nfu.edu.cn/\" + 学校要闻 + \"/index\" + str(page) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "38e13349",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 练习课本P4，涉及知识点：模块，变量，条件判断\n",
    "\n",
    "# 练习课本P33，涉及知识点：模块，变量，条件判断，time模块，for循环\n",
    "\n",
    "# 练习课本P44，涉及知识点：模块，变量，条件判断，time模块，random模块，for循环"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
